<?php
require_once "../config.php";
require_once SESSION_INCLUDE;
require_once DB;
require_once PHOTO;

session_start();

	$db = get_session_db($db_config);
	
	if(!user_is_logged($db))
	{
		header("Location:http://".LOGIN_FILE);
		exit();
	}
	
	$user = get_session_user();
	
	$photo_id = null;
	if(!isset($_POST['photo_id']))
	{
		header("HTTP/1.1 304 Not Modified");
		exit();
	} else $photo_id = $_POST['photo_id'];
	
	$photo = Photo::getPhotoFromId($db, $photo_id);
	unlink(PHOTO_DIR . "{$photo->getFilename()}");
	unlink(PHOTO_DIR . "{$photo->getHash()}".".thumb.png");
	$photo->cancel();
	
	$galery_id = $photo->get('gallery_id');
	$gallery = Gallery::getGalleryFromId($db, $galery_id);
	$gallery->set('gallery_modified', time());
	$gallery->commit();
?>
